package com.atguigu.daijia.driver.service.impl;

import com.atguigu.daijia.common.execption.GuiguException;
import com.atguigu.daijia.common.result.Result;
import com.atguigu.daijia.common.result.ResultCodeEnum;
import com.atguigu.daijia.driver.client.OcrFeignClient;
import com.atguigu.daijia.driver.service.OcrService;
import com.atguigu.daijia.model.vo.driver.DriverLicenseOcrVo;
import com.atguigu.daijia.model.vo.driver.IdCardOcrVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@Service
@SuppressWarnings({"unchecked", "rawtypes"})
public class OcrServiceImpl implements OcrService {


    @Autowired
    private OcrFeignClient ocrFeignClient;

    /**
     * 身份证识别
     */
    @Override
    public IdCardOcrVo idCardOcr(MultipartFile file) {
        log.info("调用service-driver服务的 ocr识别身份证接口");
        Result<IdCardOcrVo> ocrVoResult = ocrFeignClient.idCardOcr(file);
        if(ocrVoResult.isFail()){
            throw new GuiguException(ResultCodeEnum.FEIGN_RPC_FAIL);
        }
        return ocrVoResult.getData();
    }

    /**
     * 驾驶证识别
     * @param file
     * @return
     */
    @Override
    public DriverLicenseOcrVo driverLicenseOcr(MultipartFile file) {
        log.info("调用service-driver服务的 ocr识别驾驶证接口");
        Result<DriverLicenseOcrVo> driverLicenseOcrVoResult = ocrFeignClient.driverLicenseOcr(file);
        if(driverLicenseOcrVoResult.isFail()){
            throw new GuiguException(ResultCodeEnum.FEIGN_RPC_FAIL);
        }
        return driverLicenseOcrVoResult.getData();
    }
}
